﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TA.JSON;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Definition of a property which stores values as an enum.
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class EnumPropertyDefinition<T> : PropertyDefinition<T>
		where T : struct
	{
		/// <summary>
		/// Ctor.
		/// </summary>
		/// <param name="name"></param>
		/// <param name="shortName"></param>
		/// <param name="defaultValue"></param>
		public EnumPropertyDefinition(string name, string shortName, T defaultValue)
			: base(name, shortName, defaultValue)
		{

		}
		/// <summary>
		/// Deserializes the value of this property from the specified <see cref="JsonReader"/>.
		/// </summary>
		/// <param name="control"></param>
		/// <param name="jr"></param>
		public override void DeserializeValue(TControl control, JsonReader jr)
		{
			long l = (long)jr.Value;
			this.SetValue(control, (T)Enum.ToObject(typeof(T), l));
		}
	}
}
